#include "GMSetPosOnServer.h"
#include "ServerManager.h"
#include "TimerMS.h"

#include <iostream>

GMSetPosOnServer::GMSetPosOnServer()
{
	m_id = -1;
	m_timeStamp = 0;
	m_posX = 0.0f;
	m_posY = 0.0f;
	m_posZ = 0.0f;
}

void GMSetPosOnServer::Execute()
{
	// add to the other clients draw manager
	//TheServerManager::Instance()->SetClientPosition(m_id, Vec3fNet(m_posX, m_posY, m_posZ));
	//std::cout << "client set pos exectued ts:" << m_timeStamp << std::endl;
}

bool GMSetPosOnServer::Read(SocketMessage* sm)
{
	sm->ReadInt(&m_id);
	int ts = 0;
	sm->ReadInt(&ts);
	m_timeStamp = (unsigned int)ts;
	sm->ReadFloat(&m_posX);
	sm->ReadFloat(&m_posY);
	sm->ReadFloat(&m_posZ);

	std::cout << "Client: " << m_id << " pos was added" << std::endl;

	return true;
}

void GMSetPosOnServer::Write(SocketMessage* sm)
{
	sm->WriteString("GMSetPosOnServer");
	sm->WriteInt(m_id);
	sm->WriteInt(TheTimerMS::Instance()->GetTimeMS());
	sm->WriteFloat(m_posX);
	sm->WriteFloat(m_posY);
	sm->WriteFloat(m_posZ);
}

void GMSetPosOnServer::SetID(int i)
{
	m_id = i;
}

int GMSetPosOnServer::GetID() const
{
	return m_id;
}

Vec3fNet GMSetPosOnServer::GetPos() const
{
	return Vec3fNet(m_posX, m_posY, m_posZ);
}

void GMSetPosOnServer::SetPos(const Vec3fNet& pos)
{
	m_posX = pos.x;
	m_posY = pos.y;
	m_posZ = pos.z;
}